package PageClassTable;

import page.Page;
import page.PageClass;
import utils.JdbcUtils;

import javax.swing.*;
import java.util.List;
import java.util.Map;

public class UpdataPageClass {
    public static void init(int power){
        JFrame frame=new JFrame();
        List<Map<String, Object>> datas= JdbcUtils.JdbcQuery("SELECT * FROM page_class");
        int sum=0;
        String[] options=new String[datas.size()];
        for(Map<String,Object> map : datas){
            for(String key : map.keySet()) {
                if (key.equals("page_class_name")) options[sum++] = (String) map.get(key);
            }
        }
        String info1 = (String)JOptionPane.showInputDialog(frame,"请输入你的选项：","修改",JOptionPane.QUESTION_MESSAGE,null,options,options[0]);
        if(!info1.isEmpty()){
            String info2 = JOptionPane.showInputDialog(frame,"修改为:","输入",JOptionPane.WARNING_MESSAGE);
            if(!info2.isEmpty()){
                JdbcUtils.JdbcUpdate(PageClass.sql_updataClass,info2,info1);
                JdbcUtils.JdbcUpdate(Page.sql_updata_class,info2,info1);
                JOptionPane.showMessageDialog(frame,"修改成功");
            }else{
                JOptionPane.showMessageDialog(frame,"修改不许为空:");
            }
        }

    }
}
